home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / UIDEMO / VISOBJS / EVTPROC.CXX < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-01  |  2.0 KB  |  65 lines

  1.  
  2. // --------------------------- evtproc.cxx -------------------------------
  3.  
  4. #include "ui/evtbind.h"
  5. #include "ui/strseq.h"
  6. #include "ui/strview.h"
  7. #include "ui/applic.h"
  8.  
  9. #include "evtproc.h"
  10. #include "ids.h"
  11.  
  12. #if defined(__GNUC__)
  13. template class UI_EventBinding1<EventProcessor>; // Instantiate the template
  14. #endif
  15.  
  16. typedef UI_EventBinding1<EventProcessor> Bind;
  17.  
  18. const char* data[] = {
  19.     "newdata",     "database.sdf",    "reports.dat",    "memo1.doc",
  20.     "memo2.doc",   "sales.xls",       "proposal.tex",   "secret.rpt",
  21.     "eastern.xls", "western.xls",     "odyssey.prj",    "data.vis",
  22.     "hiring.doc",  "asia.pic",        "mickey.gif",     "einstein.jpg",
  23.     "gcc-2.7.2.tar.gz", 0
  24. };
  25.  
  26. EventProcessor::EventProcessor (UI_Dialog& root)
  27. {
  28.     UI_StringSequence& seq = (UI_StringSequence&) root[ID_LEFT]->Model();
  29.     for (short i = 0; data[i] != 0; i++)
  30.         seq.Add (data[i]);
  31.     root[ID_R_TO_L]->Disable();
  32.     Bind b (this, &EventProcessor::HandleSelectEvent);
  33.     root.AddEventDependent (Event_Select, b);
  34. }
  35.  
  36.  
  37. static void MoveData (UI_StringViewMultiSel* from, UI_StringViewMultiSel* to)
  38. {
  39.     CL_IntegerSet& s = from->Selection ();
  40.     UI_StringSequence& fromSeq = (UI_StringSequence&) from->Model();
  41.     UI_StringSequence& toSeq   = (UI_StringSequence&) to  ->Model();
  42.     fromSeq.Move (s, toSeq);
  43. }
  44.  
  45. bool EventProcessor::HandleSelectEvent (UI_Event& e)
  46. {
  47.     UI_ViewID id = e.Origin()->ViewID();
  48.     if (id == ID_DONE)
  49.         YACLApp()->End();
  50.     if (id != ID_L_TO_R && id != ID_R_TO_L)
  51.         return FALSE;
  52.     UI_Dialog& dlg = *(UI_Dialog*) e.Destination();
  53.     UI_StringViewMultiSel* lbox = (UI_StringViewMultiSel*) dlg[ID_LEFT];
  54.     UI_StringViewMultiSel* rbox = (UI_StringViewMultiSel*) dlg[ID_RIGHT];
  55.     if (id == ID_L_TO_R)
  56.         MoveData (lbox, rbox);
  57.     else
  58.         MoveData (rbox, lbox);
  59.     long lSize = ((UI_StringSequence&) lbox->Model()).Size();
  60.     long rSize = ((UI_StringSequence&) rbox->Model()).Size();
  61.     dlg[ID_L_TO_R]->SetEnabledState (lSize > 0);
  62.     dlg[ID_R_TO_L]->SetEnabledState (rSize > 0);
  63.     return TRUE;
  64. }
  65.